package com.winai.launcher.manager;

import android.content.Context;

import com.winai.launcher.bean.AiMediaBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：康少
 * 时间：2020/8/14 0014
 * 说明：ai媒体的当前播放的信息
 */
public class AiMediaCurrentInfoManager {
    private static AiMediaCurrentInfoManager mInstance;
    private Context mContext;
    private int currentIndex = 0;//当前播放列表的下标
    private List<AiMediaBean> mAiMediaBeanList;//当前播放列表

    public static AiMediaCurrentInfoManager getInstance(Context context) {
        if (mInstance == null) {
            synchronized (AiMediaCurrentInfoManager.class) {
                if (mInstance == null) {
                    mInstance = new AiMediaCurrentInfoManager(context);
                }
            }
        }
        return mInstance;
    }

    public AiMediaCurrentInfoManager() {
        try {
            throw new Exception("AiMediaCurrentInfoManager 不允许实例化");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private AiMediaCurrentInfoManager(Context mContext) {
        this.mContext = mContext;
        init();
    }

    private void init() {
        mAiMediaBeanList = new ArrayList<>();
    }

    public void setMediaInfoList(List<AiMediaBean> beanList) {
        if (!mAiMediaBeanList.isEmpty()) {
            mAiMediaBeanList.clear();
        }
        this.mAiMediaBeanList.addAll(beanList);
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }

    public AiMediaBean getCurrentMediaInfo() {
        if (!mAiMediaBeanList.isEmpty()) {
            return mAiMediaBeanList.get(currentIndex);
        } else {
            return null;
        }
    }
}
